﻿using System;
using System.Collections.Generic;

using System.Text;
using Portal.Interface;
using Portal.Environment;
using Portal.Language;
using System.Data;
using System.Data.SqlClient;

namespace Portal.CMS
{
    public class UpdateLawDocumentSigner : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "UpdateLawDocumentSigner";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Cập nhật người ký");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }

        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            try
            {

                AjaxPro.Utility.RegisterTypeForAjax(typeof(UpdateLawDocumentSigner));
                Environment.Environments.CheckSessionTimeOut(true);

                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new LawDocumentSigner().PermissionTypes, "LawDocumentSigner");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateLawDocumentSigner", new LawDocumentSigner().WebPartId, null, true);

                string LawDocumentSignerId = System.Web.HttpContext.Current.Request["LawDocumentSignerId"];
                LawDocumentSignerCls LawDocumentSignerCls = new LawDocumentSignerBLL().CreateModel(LawDocumentSignerId);
                if (LawDocumentSignerCls == null)
                {
                    return Environment.Environments.GetRecordNotFound();
                }
                string RetHtml =
                    WebPartUtilities.AttachJavascript("Portal.CMS", "LawDocumentSigner.js") +
                                 Environment.Environments.GetFormDialog(
                                 "      <table>" +
                                 "          <tr>" +
                                 "              <td>" + ResourceBLL.GetText(WebPartId,"UpdateSubject","người ký:") + "</td>" +
                                 "              <td><input class=cssTextBoxDialog id=txtSubject value=\"" + LawDocumentSignerCls.Subject + "\"></td>" +
                                 "          </tr>" +
                                 "          <tr>" +
                                 "              <td></td>" +
                                 "              <td><input type=button class=cssSaveButton onclick=javascript:ClientSaveUpdateLawDocumentSigner('" + LawDocumentSignerId + "'); value=\"" + ResourceBLL.GetText(WebPartId,"UpdateLawDocumentSignerSaveButton","Ghi lại") + "\"><input type=button class=cssCancelButton onclick=javascript:window.close(); value=\"" + ResourceBLL.GetText(WebPartId,"UpdateLawDocumentSignerCancelButton","Thoát") + "\"></td>" +
                                 "          </tr>" +
                                 "      </table>",Title);
                return RetHtml;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideUpdateLawDocumentSigner(string LawDocumentSignerId,string LawDocumentSignerName)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new LawDocumentSigner().PermissionTypes, "LawDocumentSigner");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateLawDocumentSigner", new LawDocumentSigner().WebPartId, null, true);

                if (LawDocumentSignerName.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId,"EnterName","Nhập tên nhóm vai trò"));
                new LawDocumentSignerBLL().UpdateLawDocumentSigner(null,LawDocumentSignerId, LawDocumentSignerName);
                return ResourceBLL.GetText(WebPartId,"MessageUpdateOk","Cập nhật thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }
    }
}